/*
* 匿名函数
* */
fun main() {
    val total: Int = "Mississippi".count()

    val totals: Int = "Mississippi".count({ letter -> letter == 's' })
    println(total)
    println(totals)

    //变量的类型是一个匿名函数
    //func定义 & 赋值
    val blessingFunc: () -> String
    blessingFunc = {
        val holiday = "new year"
        "happy $holiday"
    }
    println(blessingFunc())

    ///func定义 & 赋值
    val blessingFunc02: () -> String = {
        val holiday = "new year 02"
        "happy $holiday"
    }
    println(blessingFunc02())

    //传参
    val blessingFunc03: (String) -> String = { name ->
        val holiday = "new year 03"
        "$name , happy $holiday"
    }
    println(blessingFunc03("jack"))

    //it
    val blessingFunc04: (String) -> String = {
        val holiday = "new year 04"
        "$it , happy $holiday"
    }
    println(blessingFunc04("jack"))

    //返回值类型推断，自动返回最后一行数据
    val blessingFunc05 = {
        val holiday = "new year 05"
        " happy $holiday"
    }
    println(blessingFunc05())

    val blessingFunc06: (String, Int) -> String = { name, year ->
        val holiday = "new year "
        "$name , happy $holiday$year"
    }
    println(blessingFunc06("jack", 2024))

    //传参类型推断
    val blessingFunc07 = { name:String, year:Int ->
        val holiday = "new year "
        "$name , happy $holiday$year"
    }
    println(blessingFunc07("jack", 2027))


}